import 'package:flutter/material.dart';
import 'package:jd_shopping/services/ScreenAdaper.dart';
import 'package:jd_shopping/pages/CartShop/CartNum.dart';
import 'package:jd_shopping/pages/Providers/CartShow.dart';
import 'package:provider/provider.dart';

class CartItem extends StatefulWidget {
  final Map _itemData;
  CartItem(this._itemData,{Key key}) : super(key: key);
  _CartItemState createState() => _CartItemState();
}

class _CartItemState extends State<CartItem> {
   Map _itemData;
   void initState() {
    // TODO: implement initState
    super.initState();
    this._itemData=widget._itemData;
  }
  @override
  Widget build(BuildContext context) {
     ScreenAdaper.init(context);
     var cartProvider = Provider.of<CartsShow>(context);
     return Container(
      height: ScreenAdaper.height(170),
      padding: EdgeInsets.all(5),
      decoration: BoxDecoration(
          border: Border(bottom: BorderSide(width: 1, color: Colors.black12)),
          color: Colors.white
          ),
      child: Row(
        children: <Widget>[
          Container(
            width: ScreenAdaper.width(60),
            child: Checkbox(
              value: this._itemData['checked'],
              onChanged: (val) {
                setState(() {
                  this._itemData['checked'] = !this._itemData['checked'];
                  cartProvider.itemChage();
                });
              },
              activeColor: Colors.pink,
            ),
          ),
          Container(
            width: ScreenAdaper.width(160),
            child: Image.network(
                this._itemData['pic'],
                fit: BoxFit.cover),
          ),
          Expanded(
            flex: 1,
            child: Container(
              padding: EdgeInsets.fromLTRB(10, 10, 10, 5),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                    Align( 
                       alignment: Alignment.centerLeft,
                       child: Text(this._itemData['title'],
                       maxLines: 2,textAlign: TextAlign.left),
                    ),
                   Align( 
                      alignment: Alignment.centerLeft,
                      child: Text("${_itemData["selectedAttr"]}",
                      maxLines: 2,textAlign: TextAlign.left),
                   ),
                  SizedBox(height:10),
                  Stack(
                    children: <Widget>[
                      Align(
                        alignment: Alignment.centerLeft,
                        child: Text('${this._itemData['price']}',style: TextStyle(
                          color: Colors.red
                        )
                        ),
                      ),
                      Align(
                        alignment: Alignment.centerRight,
                        child: CartNum(_itemData),
                      )
                    ],
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}